<!DOCTYPE html>
<html>

<head>
    <meta charset="utf-8">
    <title></title>
</head>

<body>
</body>
<script>
    (function () {
        var obj = {
            name: "My tree",
            childer: [{
                name: "hello",
                childer: [{
                    name: "hellohahah"
                }, {
                    name: "wathaha",
                    childer: [{
                        "name": "jlsdjlkdjlsakdj",
                        childer: [{
                            "name": "adasdlja879789sad"
                        }]
                    }]
                }]
            }, {
                name: "wat",
                childer: [{
                    name: "hellohahah"
                }, {
                    name: "wathaha"
                }]
            }, {
                name: "child folder",
                childer: [{
                    name: "hello2uuhuhuiuhi"
                }, {
                    name: "watasjdoiusdfoi"
                }]
            }]
        };


         function creatDom(objChilder, hNum) {
             if(!objChilder) return "";
             if(objChilder.length==0)  return "";
             var result = "";
            for (var i = 0; i < objChilder.length; i++) { //循环3次
                var item = objChilder[i];
                result += hNum + item["name"] + "\n" + creatDom(item["childer"], hNum + "  ");
            }
             return result;
        }

        var arr = [];
        arr.push(obj);
        console.log(creatDom(arr, ""));

    })();
</script>

</html>